import gevent
from gevent import monkey
import time
monkey.patch_all()  # 自动将time.sleep() 替换未 gevent.sleep()


def task01(n):
    for i in range(n):
        print("task01", i)
        time.sleep(0.1)
        # gevent.sleep(0.1)


def task02(n):
    for i in range(n):
        print("task02", i)
        time.sleep(0.1)
        # gevent.sleep(0.1)


def task03(n):
    for i in range(n):
        print("task03", i)
        time.sleep(0.1)
        # gevent.sleep(0.1)


if __name__ == "__main__":
    gevent.joinall([
        gevent.spawn(task01, 5),
        gevent.spawn(task02, 5),
        gevent.spawn(task03, 5)
    ])
